package com.dajiba.demo

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.annotation.LayoutRes
import androidx.core.view.get
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.LogUtils
import kotlinx.android.synthetic.main.fragment_page.*

class PageFragment : Fragment() {

    private var mView: View? = null
    private var mChildView: View? = null

    fun setChildView(view: View): PageFragment {
        mChildView = view
        return this
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        if (mView == null) {
            mView = inflater.inflate(R.layout.fragment_page, null)
            (mView as ViewGroup).addView(mChildView)
        }
        return mView
    }

    @SuppressLint("ClickableViewAccessibility")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mView?.setOnTouchListener(object :View.OnTouchListener{
            override fun onTouch(v: View?, event: MotionEvent?): Boolean {
                when (event?.getAction()) {
                    MotionEvent.ACTION_MOVE -> LogUtils.d("PARENT_ACTION_MOVE")
                    MotionEvent.ACTION_DOWN -> LogUtils.d("PARENT_ACTION_DOWN")
                    MotionEvent.ACTION_UP -> LogUtils.d("PARENT_ACTION_UP")
                }
                return false
            }
        })
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
    }
}